2 ( function ( $, mw
, OO
) {
4 var ApiSandbox
, Util
, WidgetMethods
, Validators
,
5 $content
, panel
, booklet
, oldhash
, windowManager
, fullscreenButton
,
10 suppressErrors
= true,
11 updatingBooklet
= false,
17 getApiValue: function () {
18 return this.getValue();
20 setApiValue: function ( v
) {
21 if ( v
=== undefined ) {
22 v
= this.paramInfo
[ 'default' ];
26 apiCheckValid: function () {
28 return this.isValid().done( function ( ok
) {
29 ok
= ok
|| suppressErrors
;
30 that
.setIcon( ok
? null : 'alert' );
31 that
.setIconTitle( ok
? '' : mw
.message( 'apisandbox-alert-field' ).plain() );
36 dateTimeInputWidget
: {
37 isValid: function () {
38 var ok
= !Util
.apiBool( this.paramInfo
.required
) || this.getApiValue() !== '';
39 return $.Deferred().resolve( ok
).promise();
44 alertTokenError: function ( code
, error
) {
45 windowManager
.openWindow( 'errorAlert', {
47 'apisandbox-results-fixtoken-fail', this.paramInfo
.tokentype
53 label
: OO
.ui
.msg( 'ooui-dialog-process-dismiss' ),
59 fetchToken: function () {
61 return api
.getToken( this.paramInfo
.tokentype
)
62 .done( this.setApiValue
.bind( this ) )
63 .fail( this.alertTokenError
.bind( this ) )
64 .always( this.popPending
.bind( this ) );
66 setApiValue: function ( v
) {
67 WidgetMethods
.textInputWidget
.setApiValue
.call( this, v
);
68 if ( v
=== '123ABC' ) {
75 getApiValueForDisplay: function () {
81 getApiValue: function () {
82 return this.getValue() ? 1 : undefined;
84 setApiValue: function ( v
) {
85 this.setValue( Util
.apiBool( v
) );
87 apiCheckValid: function () {
88 return $.Deferred().resolve( true ).promise();
93 getApiValue: function () {
94 var item
= this.getMenu().getSelectedItem();
95 return item
=== null ? undefined : item
.getData();
97 setApiValue: function ( v
) {
98 var menu
= this.getMenu();
100 if ( v
=== undefined ) {
101 v
= this.paramInfo
[ 'default' ];
103 if ( v
=== undefined ) {
106 menu
.selectItemByData( String( v
) );
109 apiCheckValid: function () {
110 var ok
= this.getApiValue() !== undefined || suppressErrors
;
111 this.setIcon( ok
? null : 'alert' );
112 this.setIconTitle( ok
? '' : mw
.message( 'apisandbox-alert-field' ).plain() );
113 return $.Deferred().resolve( ok
).promise();
118 getApiValue: function () {
119 return this.getItemsData().join( '|' );
121 setApiValue: function ( v
) {
122 this.setItemsFromData( v
=== undefined || v
=== '' ? [] : String( v
).split( '|' ) );
124 apiCheckValid: function () {
125 var ok
= this.getApiValue() !== undefined || suppressErrors
;
126 this.setIcon( ok
? null : 'alert' );
127 this.setIconTitle( ok
? '' : mw
.message( 'apisandbox-alert-field' ).plain() );
128 return $.Deferred().resolve( ok
).promise();
133 getApiValue: function () {
134 return this.isDisabled() ? undefined : this.widget
.getApiValue();
136 setApiValue: function ( v
) {
137 this.setDisabled( v
=== undefined );
138 this.widget
.setApiValue( v
);
140 apiCheckValid: function () {
141 if ( this.isDisabled() ) {
142 return $.Deferred().resolve( true ).promise();
144 return this.widget
.apiCheckValid();
150 single: function () {
151 var v
= this.isDisabled() ? this.paramInfo
[ 'default' ] : this.getApiValue();
152 return v
=== undefined ? [] : [ { value
: v
, path
: this.paramInfo
.submodules
[ v
] } ];
155 var map
= this.paramInfo
.submodules
,
156 v
= this.isDisabled() ? this.paramInfo
[ 'default' ] : this.getApiValue();
157 return v
=== undefined || v
=== '' ? [] : $.map( String( v
).split( '|' ), function ( v
) {
158 return { value
: v
, path
: map
[ v
] };
164 getApiValueForDisplay: function () {
167 getApiValue: function () {
168 return this.getValue();
170 setApiValue: function () {
173 apiCheckValid: function () {
174 var ok
= this.getValue() !== null || suppressErrors
;
175 this.setIcon( ok
? null : 'alert' );
176 this.setIconTitle( ok
? '' : mw
.message( 'apisandbox-alert-field' ).plain() );
177 return $.Deferred().resolve( ok
).promise();
183 generic: function () {
184 return !Util
.apiBool( this.paramInfo
.required
) || this.getApiValue() !== '';
189 * @class mw.special.ApiSandbox.Utils
194 * Fetch API module info
196 * @param {string} module Module to fetch data for
197 * @return {jQuery.Promise}
199 fetchModuleInfo: function ( module
) {
201 deferred
= $.Deferred();
203 if ( moduleInfoCache
.hasOwnProperty( module
) ) {
205 .resolve( moduleInfoCache
[ module
] )
206 .promise( { abort: function () {} } );
208 apiPromise
= api
.post( {
212 uselang
: mw
.config
.get( 'wgUserLanguage' )
213 } ).done( function ( data
) {
216 if ( data
.warnings
&& data
.warnings
.paraminfo
) {
217 deferred
.reject( '???', data
.warnings
.paraminfo
[ '*' ] );
221 info
= data
.paraminfo
.modules
;
222 if ( !info
|| info
.length
!== 1 || info
[ 0 ].path
!== module
) {
223 deferred
.reject( '???', 'No module data returned' );
227 moduleInfoCache
[ module
] = info
[ 0 ];
228 deferred
.resolve( info
[ 0 ] );
229 } ).fail( function ( code
, details
) {
230 if ( code
=== 'http' ) {
231 details
= 'HTTP error: ' + details
.exception
;
232 } else if ( details
.error
) {
233 details
= details
.error
.info
;
235 deferred
.reject( code
, details
);
238 .promise( { abort
: apiPromise
.abort
} );
243 * Mark all currently-in-use tokens as bad
245 markTokensBad: function () {
246 var page
, subpages
, i
,
247 checkPages
= [ pages
.main
];
249 while ( checkPages
.length
) {
250 page
= checkPages
.shift();
252 if ( page
.tokenWidget
) {
253 api
.badToken( page
.tokenWidget
.paramInfo
.tokentype
);
256 subpages
= page
.getSubpages();
257 for ( i
= 0; i
< subpages
.length
; i
++ ) {
258 if ( pages
.hasOwnProperty( subpages
[ i
].key
) ) {
259 checkPages
.push( pages
[ subpages
[ i
].key
] );
266 * Test an API boolean
268 * @param {Mixed} value
271 apiBool: function ( value
) {
272 return value
!== undefined && value
!== false;
276 * Create a widget for a parameter.
278 * @param {Object} pi Parameter info from API
279 * @param {Object} opts Additional options
280 * @return {OO.ui.Widget}
282 createWidgetForParameter: function ( pi
, opts
) {
283 var widget
, innerWidget
, finalWidget
, items
, $button
, $content
, func
,
290 widget
= new OO
.ui
.ToggleSwitchWidget();
291 widget
.paramInfo
= pi
;
292 $.extend( widget
, WidgetMethods
.toggleSwitchWidget
);
293 pi
.required
= true; // Avoid wrapping in the non-required widget
298 if ( pi
.tokentype
) {
299 widget
= new TextInputWithIndicatorWidget( {
301 indicator
: 'previous',
302 indicatorTitle
: mw
.message( 'apisandbox-fetch-token' ).text(),
303 required
: Util
.apiBool( pi
.required
)
306 } else if ( Util
.apiBool( pi
.multi
) ) {
307 widget
= new OO
.ui
.CapsuleMultiSelectWidget( {
310 widget
.paramInfo
= pi
;
311 $.extend( widget
, WidgetMethods
.capsuleWidget
);
313 widget
= new OO
.ui
.TextInputWidget( {
314 required
: Util
.apiBool( pi
.required
)
317 if ( !Util
.apiBool( pi
.multi
) ) {
318 widget
.paramInfo
= pi
;
319 $.extend( widget
, WidgetMethods
.textInputWidget
);
320 widget
.setValidation( Validators
.generic
);
322 if ( pi
.tokentype
) {
323 $.extend( widget
, WidgetMethods
.tokenWidget
);
324 widget
.input
.paramInfo
= pi
;
325 $.extend( widget
.input
, WidgetMethods
.textInputWidget
);
326 $.extend( widget
.input
, WidgetMethods
.tokenWidget
);
327 widget
.on( 'indicator', widget
.fetchToken
, [], widget
);
332 widget
= new OO
.ui
.TextInputWidget( {
334 required
: Util
.apiBool( pi
.required
)
336 widget
.paramInfo
= pi
;
337 $.extend( widget
, WidgetMethods
.textInputWidget
);
338 widget
.setValidation( Validators
.generic
);
342 widget
= new OO
.ui
.TextInputWidget( {
344 required
: Util
.apiBool( pi
.required
)
346 widget
.paramInfo
= pi
;
347 $.extend( widget
, WidgetMethods
.textInputWidget
);
348 $.extend( widget
, WidgetMethods
.passwordWidget
);
349 widget
.setValidation( Validators
.generic
);
354 widget
= new OO
.ui
.NumberInputWidget( {
355 required
: Util
.apiBool( pi
.required
),
358 widget
.setIcon
= widget
.input
.setIcon
.bind( widget
.input
);
359 widget
.setIconTitle
= widget
.input
.setIconTitle
.bind( widget
.input
);
360 widget
.isValid
= widget
.input
.isValid
.bind( widget
.input
);
361 widget
.paramInfo
= pi
;
362 $.extend( widget
, WidgetMethods
.textInputWidget
);
363 if ( Util
.apiBool( pi
.enforcerange
) ) {
364 widget
.setRange( pi
.min
|| -Infinity
, pi
.max
|| Infinity
);
370 widget
= new OO
.ui
.NumberInputWidget( {
371 required
: Util
.apiBool( pi
.required
),
374 widget
.setIcon
= widget
.input
.setIcon
.bind( widget
.input
);
375 widget
.setIconTitle
= widget
.input
.setIconTitle
.bind( widget
.input
);
376 widget
.isValid
= widget
.input
.isValid
.bind( widget
.input
);
377 widget
.input
.setValidation( function ( value
) {
378 return value
=== 'max' || widget
.validateNumber( value
);
380 widget
.paramInfo
= pi
;
381 $.extend( widget
, WidgetMethods
.textInputWidget
);
382 widget
.setRange( pi
.min
|| 0, mw
.config
.get( 'apihighlimits' ) ? pi
.highmax
: pi
.max
);
387 widget
= new mw
.widgets
.datetime
.DateTimeInputWidget( {
389 format
: '${year|0}-${month|0}-${day|0}T${hour|0}:${minute|0}:${second|0}${zone|short}'
391 required
: Util
.apiBool( pi
.required
),
394 widget
.paramInfo
= pi
;
395 $.extend( widget
, WidgetMethods
.textInputWidget
);
396 $.extend( widget
, WidgetMethods
.dateTimeInputWidget
);
397 multiMode
= 'indicator';
401 widget
= new OO
.ui
.SelectFileWidget();
402 widget
.paramInfo
= pi
;
403 $.extend( widget
, WidgetMethods
.uploadWidget
);
407 items
= $.map( mw
.config
.get( 'wgFormattedNamespaces' ), function ( name
, ns
) {
409 name
= mw
.message( 'blanknamespace' ).text();
411 return new OO
.ui
.MenuOptionWidget( { data
: ns
, label
: name
} );
412 } ).sort( function ( a
, b
) {
413 return a
.data
- b
.data
;
415 if ( Util
.apiBool( pi
.multi
) ) {
416 widget
= new OO
.ui
.CapsuleMultiSelectWidget( {
417 menu
: { items
: items
}
419 widget
.paramInfo
= pi
;
420 $.extend( widget
, WidgetMethods
.capsuleWidget
);
422 widget
= new OO
.ui
.DropdownWidget( {
423 menu
: { items
: items
}
425 widget
.paramInfo
= pi
;
426 $.extend( widget
, WidgetMethods
.dropdownWidget
);
431 if ( !$.isArray( pi
.type
) ) {
432 throw new Error( 'Unknown parameter type ' + pi
.type
);
435 items
= $.map( pi
.type
, function ( v
) {
436 return new OO
.ui
.MenuOptionWidget( { data
: String( v
), label
: String( v
) } );
438 if ( Util
.apiBool( pi
.multi
) ) {
439 widget
= new OO
.ui
.CapsuleMultiSelectWidget( {
440 menu
: { items
: items
}
442 widget
.paramInfo
= pi
;
443 $.extend( widget
, WidgetMethods
.capsuleWidget
);
444 if ( Util
.apiBool( pi
.submodules
) ) {
445 widget
.getSubmodules
= WidgetMethods
.submoduleWidget
.multi
;
446 widget
.on( 'change', ApiSandbox
.updateUI
);
449 widget
= new OO
.ui
.DropdownWidget( {
450 menu
: { items
: items
}
452 widget
.paramInfo
= pi
;
453 $.extend( widget
, WidgetMethods
.dropdownWidget
);
454 if ( Util
.apiBool( pi
.submodules
) ) {
455 widget
.getSubmodules
= WidgetMethods
.submoduleWidget
.single
;
456 widget
.getMenu().on( 'choose', ApiSandbox
.updateUI
);
463 if ( Util
.apiBool( pi
.multi
) && multiMode
!== 'none' ) {
464 innerWidget
= widget
;
465 switch ( multiMode
) {
467 $content
= innerWidget
.$element
;
471 $button
= innerWidget
.$indicator
;
472 $button
.css( 'cursor', 'pointer' );
473 $button
.attr( 'tabindex', 0 );
474 $button
.parent().append( $button
);
475 innerWidget
.setIndicator( 'next' );
476 $content
= innerWidget
.$element
;
480 throw new Error( 'Unknown multiMode "' + multiMode
+ '"' );
483 widget
= new OO
.ui
.CapsuleMultiSelectWidget( {
484 allowArbitrary
: true,
486 classes
: [ 'mw-apisandbox-popup' ],
490 widget
.paramInfo
= pi
;
491 $.extend( widget
, WidgetMethods
.capsuleWidget
);
494 if ( !innerWidget
.isDisabled() ) {
495 innerWidget
.apiCheckValid().done( function ( ok
) {
497 widget
.addItemsFromData( [ innerWidget
.getApiValue() ] );
498 innerWidget
.setApiValue( undefined );
504 switch ( multiMode
) {
506 innerWidget
.connect( null, { enter
: func
} );
512 keypress: function ( e
) {
513 if ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) {
522 if ( Util
.apiBool( pi
.required
) || opts
.nooptional
) {
523 finalWidget
= widget
;
525 finalWidget
= new OptionalWidget( widget
);
526 finalWidget
.paramInfo
= pi
;
527 $.extend( finalWidget
, WidgetMethods
.optionalWidget
);
528 if ( widget
.getSubmodules
) {
529 finalWidget
.getSubmodules
= widget
.getSubmodules
.bind( widget
);
530 finalWidget
.on( 'disable', function () { setTimeout( ApiSandbox
.updateUI
); } );
532 finalWidget
.setDisabled( true );
535 widget
.setApiValue( pi
[ 'default' ] );
541 * Parse an HTML string, adding target="_blank" to any links
543 * @param {string} html HTML to parse
546 parseHTML: function ( html
) {
547 var $ret
= $( $.parseHTML( html
) );
548 $ret
.filter( 'a' ).add( $ret
.find( 'a' ) )
549 .filter( '[href]:not([target])' )
550 .attr( 'target', '_blank' );
556 * Interface to ApiSandbox UI
558 * @class mw.special.ApiSandbox
560 mw
.special
.ApiSandbox
= ApiSandbox
= {
564 * Automatically called on $.ready()
569 $content
= $( '#mw-apisandbox' );
571 windowManager
= new OO
.ui
.WindowManager();
572 $( 'body' ).append( windowManager
.$element
);
573 windowManager
.addWindows( {
574 errorAlert
: new OO
.ui
.MessageDialog()
577 fullscreenButton
= new OO
.ui
.ButtonWidget( {
578 label
: mw
.message( 'apisandbox-fullscreen' ).text(),
579 title
: mw
.message( 'apisandbox-fullscreen-tooltip' ).text()
580 } ).on( 'click', ApiSandbox
.toggleFullscreen
);
582 $toolbar
= $( '<div>' )
583 .addClass( 'mw-apisandbox-toolbar' )
585 fullscreenButton
.$element
,
586 new OO
.ui
.ButtonWidget( {
587 label
: mw
.message( 'apisandbox-submit' ).text(),
588 flags
: [ 'primary', 'constructive' ]
589 } ).on( 'click', ApiSandbox
.sendRequest
).$element
,
590 new OO
.ui
.ButtonWidget( {
591 label
: mw
.message( 'apisandbox-reset' ).text(),
593 } ).on( 'click', ApiSandbox
.resetUI
).$element
596 booklet
= new OO
.ui
.BookletLayout( {
601 panel
= new OO
.ui
.PanelLayout( {
602 classes
: [ 'mw-apisandbox-container' ],
603 content
: [ booklet
],
608 pages
.main
= new ApiSandbox
.PageLayout( { key
: 'main', path
: 'main' } );
610 // Parse the current hash string
611 if ( !ApiSandbox
.loadFromHash() ) {
612 ApiSandbox
.updateUI();
615 // If the hashchange event exists, use it. Otherwise, fake it.
616 // And, of course, IE has to be dumb.
617 if ( 'onhashchange' in window
&&
618 ( document
.documentMode
=== undefined || document
.documentMode
>= 8 )
620 $( window
).on( 'hashchange', ApiSandbox
.loadFromHash
);
622 setInterval( function () {
623 if ( oldhash
!== location
.hash
) {
624 ApiSandbox
.loadFromHash();
631 .append( $( '<p>' ).append( mw
.message( 'apisandbox-intro' ).parse() ) )
633 $( '<div>', { id
: 'mw-apisandbox-ui' } )
635 .append( panel
.$element
)
638 $( window
).on( 'resize', ApiSandbox
.resizePanel
);
640 ApiSandbox
.resizePanel();
644 * Toggle "fullscreen" mode
646 toggleFullscreen: function () {
647 var $body
= $( document
.body
);
649 $body
.toggleClass( 'mw-apisandbox-fullscreen' );
650 if ( $body
.hasClass( 'mw-apisandbox-fullscreen' ) ) {
651 fullscreenButton
.setLabel( mw
.message( 'apisandbox-unfullscreen' ).text() );
652 fullscreenButton
.setTitle( mw
.message( 'apisandbox-unfullscreen-tooltip' ).text() );
653 $body
.append( $( '#mw-apisandbox-ui' ) );
655 fullscreenButton
.setLabel( mw
.message( 'apisandbox-fullscreen' ).text() );
656 fullscreenButton
.setTitle( mw
.message( 'apisandbox-fullscreen-tooltip' ).text() );
657 $content
.append( $( '#mw-apisandbox-ui' ) );
659 ApiSandbox
.resizePanel();
663 * Set the height of the panel based on the current viewport.
665 resizePanel: function () {
666 var height
= $( window
).height(),
667 contentTop
= $content
.offset().top
;
669 if ( $( document
.body
).hasClass( 'mw-apisandbox-fullscreen' ) ) {
670 height
-= panel
.$element
.offset().top
- $( '#mw-apisandbox-ui' ).offset().top
;
671 panel
.$element
.height( height
- 1 );
673 // Subtract the height of the intro text
674 height
-= panel
.$element
.offset().top
- contentTop
;
676 panel
.$element
.height( height
- 10 );
677 $( window
).scrollTop( contentTop
- 5 );
682 * Update the current query when the page hash changes
684 loadFromHash: function () {
686 hash
= location
.hash
;
688 if ( oldhash
=== hash
) {
696 // I'm surprised this doesn't seem to exist in jQuery or mw.util.
698 hash
= hash
.replace( '+', '%20' );
699 re
= /([^&=#]+)=?([^&#]*)/g;
700 while ( ( m
= re
.exec( hash
) ) ) {
701 params
[ decodeURIComponent( m
[ 1 ] ) ] = decodeURIComponent( m
[ 2 ] );
704 ApiSandbox
.updateUI( params
);
709 * Update the pages in the booklet
711 * @param {Object} [params] Optional query parameters to load
713 updateUI: function ( params
) {
714 var i
, page
, subpages
, j
, removePages
,
717 if ( !$.isPlainObject( params
) ) {
721 if ( updatingBooklet
) {
724 updatingBooklet
= true;
726 if ( params
!== undefined ) {
727 pages
.main
.loadQueryParams( params
);
729 addPages
.push( pages
.main
);
730 if ( resultPage
!== null ) {
731 addPages
.push( resultPage
);
733 pages
.main
.apiCheckValid();
736 while ( addPages
.length
) {
737 page
= addPages
.shift();
738 if ( bookletPages
[ i
] !== page
) {
739 for ( j
= i
; j
< bookletPages
.length
; j
++ ) {
740 if ( bookletPages
[ j
].getName() === page
.getName() ) {
741 bookletPages
.splice( j
, 1 );
744 bookletPages
.splice( i
, 0, page
);
745 booklet
.addPages( [ page
], i
);
749 if ( page
.getSubpages
) {
750 subpages
= page
.getSubpages();
751 for ( j
= 0; j
< subpages
.length
; j
++ ) {
752 if ( !pages
.hasOwnProperty( subpages
[ j
].key
) ) {
753 subpages
[ j
].indentLevel
= page
.indentLevel
+ 1;
754 pages
[ subpages
[ j
].key
] = new ApiSandbox
.PageLayout( subpages
[ j
] );
756 if ( params
!== undefined ) {
757 pages
[ subpages
[ j
].key
].loadQueryParams( params
);
759 addPages
.splice( j
, 0, pages
[ subpages
[ j
].key
] );
760 pages
[ subpages
[ j
].key
].apiCheckValid();
765 if ( bookletPages
.length
> i
) {
766 removePages
= bookletPages
.splice( i
, bookletPages
.length
- i
);
767 booklet
.removePages( removePages
);
770 if ( !booklet
.getCurrentPageName() ) {
771 booklet
.selectFirstSelectablePage();
774 updatingBooklet
= false;
779 * Reset button handler
781 resetUI: function () {
782 suppressErrors
= true;
784 main
: new ApiSandbox
.PageLayout( { key
: 'main', path
: 'main' } )
787 ApiSandbox
.updateUI();
791 * Submit button handler
793 sendRequest: function () {
794 var page
, subpages
, i
, query
, $result
, $focus
,
795 progress
, $progressText
, progressLoading
,
799 checkPages
= [ pages
.main
];
801 // Blur any focused widget before submit, because
802 // OO.ui.ButtonWidget doesn't take focus itself (T128054)
803 $focus
= $( '#mw-apisandbox-ui' ).find( document
.activeElement
);
804 if ( $focus
.length
) {
808 suppressErrors
= false;
810 while ( checkPages
.length
) {
811 page
= checkPages
.shift();
812 deferreds
.push( page
.apiCheckValid() );
813 page
.getQueryParams( params
, displayParams
);
814 subpages
= page
.getSubpages();
815 for ( i
= 0; i
< subpages
.length
; i
++ ) {
816 if ( pages
.hasOwnProperty( subpages
[ i
].key
) ) {
817 checkPages
.push( pages
[ subpages
[ i
].key
] );
822 $.when
.apply( $, deferreds
).done( function () {
823 if ( $.inArray( false, arguments
) !== -1 ) {
824 windowManager
.openWindow( 'errorAlert', {
825 title
: mw
.message( 'apisandbox-submit-invalid-fields-title' ).parse(),
826 message
: mw
.message( 'apisandbox-submit-invalid-fields-message' ).parse(),
830 label
: OO
.ui
.msg( 'ooui-dialog-process-dismiss' ),
838 query
= $.param( displayParams
);
840 // Force a 'fm' format with wrappedhtml=1, if available
841 if ( params
.format
!== undefined ) {
842 if ( availableFormats
.hasOwnProperty( params
.format
+ 'fm' ) ) {
843 params
.format
= params
.format
+ 'fm';
845 if ( params
.format
.substr( -2 ) === 'fm' ) {
846 params
.wrappedhtml
= 1;
850 progressLoading
= false;
851 $progressText
= $( '<span>' ).text( mw
.message( 'apisandbox-sending-request' ).text() );
852 progress
= new OO
.ui
.ProgressBarWidget( {
854 $content
: $progressText
857 $result
= $( '<div>' )
858 .append( progress
.$element
);
860 resultPage
= page
= new OO
.ui
.PageLayout( '|results|' );
861 page
.setupOutlineItem = function () {
862 this.outlineItem
.setLabel( mw
.message( 'apisandbox-results' ).text() );
864 page
.$element
.empty()
866 new OO
.ui
.FieldLayout(
867 new OO
.ui
.TextInputWidget( {
869 value
: mw
.util
.wikiScript( 'api' ) + '?' + query
871 label
: mw
.message( 'apisandbox-request-url-label' ).parse()
876 ApiSandbox
.updateUI();
877 booklet
.setPage( '|results|' );
879 location
.href
= oldhash
= '#' + query
;
882 contentType
: 'multipart/form-data',
885 var xhr
= new window
.XMLHttpRequest();
886 xhr
.upload
.addEventListener( 'progress', function ( e
) {
887 if ( !progressLoading
) {
888 if ( e
.lengthComputable
) {
889 progress
.setProgress( e
.loaded
* 100 / e
.total
);
891 progress
.setProgress( false );
895 xhr
.addEventListener( 'progress', function ( e
) {
896 if ( !progressLoading
) {
897 progressLoading
= true;
898 $progressText
.text( mw
.message( 'apisandbox-loading-results' ).text() );
900 if ( e
.lengthComputable
) {
901 progress
.setProgress( e
.loaded
* 100 / e
.total
);
903 progress
.setProgress( false );
909 .fail( function ( code
, data
) {
910 var details
= 'HTTP error: ' + data
.exception
;
913 new OO
.ui
.LabelWidget( {
914 label
: mw
.message( 'apisandbox-results-error', details
).text(),
919 .done( function ( data
, jqXHR
) {
920 var m
, loadTime
, button
,
921 ct
= jqXHR
.getResponseHeader( 'Content-Type' );
924 if ( /^text\/mediawiki-api-prettyprint-wrapped(?:;|$)/.test( ct
) ) {
925 data
= $.parseJSON( data
);
926 if ( data
.modules
.length
) {
927 mw
.loader
.load( data
.modules
);
929 $result
.append( Util
.parseHTML( data
.html
) );
930 loadTime
= data
.time
;
931 } else if ( ( m
= data
.match( /<pre[ >][\s\S]*<\/pre>/ ) ) ) {
932 $result
.append( Util
.parseHTML( m
[ 0 ] ) );
933 if ( ( m
= data
.match( /"wgBackendResponseTime":\s*(\d+)/ ) ) ) {
934 loadTime
= parseInt( m
[ 1 ], 10 );
938 .addClass( 'api-pretty-content' )
940 .appendTo( $result
);
942 if ( typeof loadTime
=== 'number' ) {
945 new OO
.ui
.LabelWidget( {
946 label
: mw
.message( 'apisandbox-request-time', loadTime
).text()
952 if ( jqXHR
.getResponseHeader( 'MediaWiki-API-Error' ) === 'badtoken' ) {
953 // Flush all saved tokens in case one of them is the bad one.
954 Util
.markTokensBad();
955 button
= new OO
.ui
.ButtonWidget( {
956 label
: mw
.message( 'apisandbox-results-fixtoken' ).text()
958 button
.on( 'click', ApiSandbox
.fixTokenAndResend
)
959 .on( 'click', button
.setDisabled
, [ true ], button
)
960 .$element
.appendTo( $result
);
967 * Handler for the "Correct token and resubmit" button
969 * Used on a 'badtoken' error, it re-fetches token parameters for all
970 * pages and then re-submits the query.
972 fixTokenAndResend: function () {
973 var page
, subpages
, i
, k
,
975 tokenWait
= { dummy
: true },
976 checkPages
= [ pages
.main
],
977 success = function ( k
) {
978 delete tokenWait
[ k
];
979 if ( ok
&& $.isEmptyObject( tokenWait
) ) {
980 ApiSandbox
.sendRequest();
983 failure = function ( k
) {
984 delete tokenWait
[ k
];
988 while ( checkPages
.length
) {
989 page
= checkPages
.shift();
991 if ( page
.tokenWidget
) {
992 k
= page
.apiModule
+ page
.tokenWidget
.paramInfo
.name
;
993 tokenWait
[ k
] = page
.tokenWidget
.fetchToken()
994 .done( success
.bind( page
.tokenWidget
, k
) )
995 .fail( failure
.bind( page
.tokenWidget
, k
) );
998 subpages
= page
.getSubpages();
999 for ( i
= 0; i
< subpages
.length
; i
++ ) {
1000 if ( pages
.hasOwnProperty( subpages
[ i
].key
) ) {
1001 checkPages
.push( pages
[ subpages
[ i
].key
] );
1006 success( 'dummy', '' );
1010 * Reset validity indicators for all widgets
1012 updateValidityIndicators: function () {
1013 var page
, subpages
, i
,
1014 checkPages
= [ pages
.main
];
1016 while ( checkPages
.length
) {
1017 page
= checkPages
.shift();
1018 page
.apiCheckValid();
1019 subpages
= page
.getSubpages();
1020 for ( i
= 0; i
< subpages
.length
; i
++ ) {
1021 if ( pages
.hasOwnProperty( subpages
[ i
].key
) ) {
1022 checkPages
.push( pages
[ subpages
[ i
].key
] );
1030 * PageLayout for API modules
1034 * @extends OO.ui.PageLayout
1036 * @param {Object} [config] Configuration options
1038 ApiSandbox
.PageLayout = function ( config
) {
1039 config
= $.extend( { prefix
: '' }, config
);
1040 this.displayText
= config
.key
;
1041 this.apiModule
= config
.path
;
1042 this.prefix
= config
.prefix
;
1043 this.paramInfo
= null;
1044 this.apiIsValid
= true;
1045 this.loadFromQueryParams
= null;
1047 this.tokenWidget
= null;
1048 this.indentLevel
= config
.indentLevel
? config
.indentLevel
: 0;
1049 ApiSandbox
.PageLayout
[ 'super' ].call( this, config
.key
, config
);
1050 this.loadParamInfo();
1052 OO
.inheritClass( ApiSandbox
.PageLayout
, OO
.ui
.PageLayout
);
1053 ApiSandbox
.PageLayout
.prototype.setupOutlineItem = function () {
1054 this.outlineItem
.setLevel( this.indentLevel
);
1055 this.outlineItem
.setLabel( this.displayText
);
1056 this.outlineItem
.setIcon( this.apiIsValid
|| suppressErrors
? null : 'alert' );
1057 this.outlineItem
.setIconTitle(
1058 this.apiIsValid
|| suppressErrors
? '' : mw
.message( 'apisandbox-alert-page' ).plain()
1063 * Fetch module information for this page's module, then create UI
1065 ApiSandbox
.PageLayout
.prototype.loadParamInfo = function () {
1066 var dynamicFieldset
, dynamicParamNameWidget
,
1068 removeDynamicParamWidget = function ( name
, layout
) {
1069 dynamicFieldset
.removeItems( [ layout
] );
1070 delete that
.widgets
[ name
];
1072 addDynamicParamWidget = function () {
1073 var name
, layout
, widget
, button
;
1075 // Check name is filled in
1076 name
= dynamicParamNameWidget
.getValue().trim();
1077 if ( name
=== '' ) {
1078 dynamicParamNameWidget
.focus();
1082 if ( that
.widgets
[ name
] !== undefined ) {
1083 windowManager
.openWindow( 'errorAlert', {
1085 'apisandbox-dynamic-error-exists', name
1090 label
: OO
.ui
.msg( 'ooui-dialog-process-dismiss' ),
1098 widget
= Util
.createWidgetForParameter( {
1105 button
= new OO
.ui
.ButtonWidget( {
1107 flags
: 'destructive'
1109 layout
= new OO
.ui
.ActionFieldLayout(
1117 button
.on( 'click', removeDynamicParamWidget
, [ name
, layout
] );
1118 that
.widgets
[ name
] = widget
;
1119 dynamicFieldset
.addItems( [ layout
], dynamicFieldset
.getItems().length
- 1 );
1122 dynamicParamNameWidget
.setValue( '' );
1125 this.$element
.empty()
1126 .append( new OO
.ui
.ProgressBarWidget( {
1128 text
: mw
.message( 'apisandbox-loading', this.displayText
).text()
1131 Util
.fetchModuleInfo( this.apiModule
)
1132 .done( function ( pi
) {
1133 var prefix
, i
, j
, dl
, widget
, $widgetLabel
, widgetField
, helpField
, tmp
, flag
, count
,
1135 deprecatedItems
= [],
1137 filterFmModules = function ( v
) {
1138 return v
.substr( -2 ) !== 'fm' ||
1139 !availableFormats
.hasOwnProperty( v
.substr( 0, v
.length
- 2 ) );
1141 widgetLabelOnClick = function () {
1142 var f
= this.getField();
1143 if ( $.isFunction( f
.setDisabled
) ) {
1144 f
.setDisabled( false );
1146 if ( $.isFunction( f
.focus
) ) {
1150 doNothing = function () {};
1152 // This is something of a hack. We always want the 'format' and
1153 // 'action' parameters from the main module to be specified,
1154 // and for 'format' we also want to simplify the dropdown since
1155 // we always send the 'fm' variant.
1156 if ( that
.apiModule
=== 'main' ) {
1157 for ( i
= 0; i
< pi
.parameters
.length
; i
++ ) {
1158 if ( pi
.parameters
[ i
].name
=== 'action' ) {
1159 pi
.parameters
[ i
].required
= true;
1160 delete pi
.parameters
[ i
][ 'default' ];
1162 if ( pi
.parameters
[ i
].name
=== 'format' ) {
1163 tmp
= pi
.parameters
[ i
].type
;
1164 for ( j
= 0; j
< tmp
.length
; j
++ ) {
1165 availableFormats
[ tmp
[ j
] ] = true;
1167 pi
.parameters
[ i
].type
= $.grep( tmp
, filterFmModules
);
1168 pi
.parameters
[ i
][ 'default' ] = 'json';
1169 pi
.parameters
[ i
].required
= true;
1174 // Hide the 'wrappedhtml' parameter on format modules
1175 if ( pi
.group
=== 'format' ) {
1176 pi
.parameters
= $.grep( pi
.parameters
, function ( p
) {
1177 return p
.name
!== 'wrappedhtml';
1181 that
.paramInfo
= pi
;
1183 items
.push( new OO
.ui
.FieldLayout(
1184 new OO
.ui
.Widget( {} ).toggle( false ), {
1186 label
: Util
.parseHTML( pi
.description
)
1190 if ( pi
.helpurls
.length
) {
1191 buttons
.push( new OO
.ui
.PopupButtonWidget( {
1192 label
: mw
.message( 'apisandbox-helpurls' ).text(),
1195 $content
: $( '<ul>' ).append( $.map( pi
.helpurls
, function ( link
) {
1196 return $( '<li>' ).append( $( '<a>', {
1206 if ( pi
.examples
.length
) {
1207 buttons
.push( new OO
.ui
.PopupButtonWidget( {
1208 label
: mw
.message( 'apisandbox-examples' ).text(),
1211 $content
: $( '<ul>' ).append( $.map( pi
.examples
, function ( example
) {
1213 href
: '#' + example
.query
,
1214 html
: example
.description
1216 a
.find( 'a' ).contents().unwrap(); // Can't nest links
1217 return $( '<li>' ).append( a
);
1223 if ( buttons
.length
) {
1224 items
.push( new OO
.ui
.FieldLayout(
1225 new OO
.ui
.ButtonGroupWidget( {
1227 } ), { align
: 'top' }
1231 if ( pi
.parameters
.length
) {
1232 prefix
= that
.prefix
+ pi
.prefix
;
1233 for ( i
= 0; i
< pi
.parameters
.length
; i
++ ) {
1234 widget
= Util
.createWidgetForParameter( pi
.parameters
[ i
] );
1235 that
.widgets
[ prefix
+ pi
.parameters
[ i
].name
] = widget
;
1236 if ( pi
.parameters
[ i
].tokentype
) {
1237 that
.tokenWidget
= widget
;
1241 dl
.append( $( '<dd>', {
1242 addClass
: 'description',
1243 append
: Util
.parseHTML( pi
.parameters
[ i
].description
)
1245 if ( pi
.parameters
[ i
].info
&& pi
.parameters
[ i
].info
.length
) {
1246 for ( j
= 0; j
< pi
.parameters
[ i
].info
.length
; j
++ ) {
1247 dl
.append( $( '<dd>', {
1249 append
: Util
.parseHTML( pi
.parameters
[ i
].info
[ j
] )
1255 switch ( pi
.parameters
[ i
].type
) {
1258 count
= mw
.config
.get( 'wgFormattedNamespaces' ).length
;
1262 if ( pi
.parameters
[ i
].highmax
!== undefined ) {
1263 dl
.append( $( '<dd>', {
1265 append
: Util
.parseHTML( mw
.message(
1266 'api-help-param-limit2', pi
.parameters
[ i
].max
, pi
.parameters
[ i
].highmax
1270 dl
.append( $( '<dd>', {
1272 append
: Util
.parseHTML( mw
.message(
1273 'api-help-param-limit', pi
.parameters
[ i
].max
1281 if ( pi
.parameters
[ i
].min
!== undefined ) {
1284 if ( pi
.parameters
[ i
].max
!== undefined ) {
1288 dl
.append( $( '<dd>', {
1290 append
: Util
.parseHTML( mw
.message(
1291 'api-help-param-integer-' + tmp
,
1292 Util
.apiBool( pi
.parameters
[ i
].multi
) ? 2 : 1,
1293 pi
.parameters
[ i
].min
, pi
.parameters
[ i
].max
1300 if ( $.isArray( pi
.parameters
[ i
].type
) ) {
1302 count
= pi
.parameters
[ i
].type
.length
;
1306 if ( Util
.apiBool( pi
.parameters
[ i
].multi
) ) {
1308 if ( flag
&& !( widget
instanceof OO
.ui
.CapsuleMultiSelectWidget
) &&
1310 widget
instanceof OptionalWidget
&&
1311 widget
.widget
instanceof OO
.ui
.CapsuleMultiSelectWidget
1314 tmp
.push( mw
.message( 'api-help-param-multi-separate' ).parse() );
1316 if ( count
> pi
.parameters
[ i
].lowlimit
) {
1318 mw
.message( 'api-help-param-multi-max',
1319 pi
.parameters
[ i
].lowlimit
, pi
.parameters
[ i
].highlimit
1324 dl
.append( $( '<dd>', {
1326 append
: Util
.parseHTML( tmp
.join( ' ' ) )
1330 helpField
= new OO
.ui
.FieldLayout(
1333 classes
: [ 'mw-apisandbox-spacer' ]
1336 classes
: [ 'mw-apisandbox-help-field' ],
1341 $widgetLabel
= $( '<span>' );
1342 widgetField
= new OO
.ui
.FieldLayout(
1346 classes
: [ 'mw-apisandbox-widget-field' ],
1347 label
: prefix
+ pi
.parameters
[ i
].name
,
1348 $label
: $widgetLabel
1352 // FieldLayout only does click for InputElement
1353 // widgets. So supply our own click handler.
1354 $widgetLabel
.on( 'click', widgetLabelOnClick
.bind( widgetField
) );
1356 // Don't grey out the label when the field is disabled,
1357 // it makes it too hard to read and our "disabled"
1358 // isn't really disabled.
1359 widgetField
.onFieldDisable
= doNothing
;
1361 if ( Util
.apiBool( pi
.parameters
[ i
].deprecated
) ) {
1362 deprecatedItems
.push( widgetField
, helpField
);
1364 items
.push( widgetField
, helpField
);
1369 if ( !pi
.parameters
.length
&& !Util
.apiBool( pi
.dynamicparameters
) ) {
1370 items
.push( new OO
.ui
.FieldLayout(
1371 new OO
.ui
.Widget( {} ).toggle( false ), {
1373 label
: Util
.parseHTML( mw
.message( 'apisandbox-no-parameters' ).parse() )
1378 that
.$element
.empty();
1380 new OO
.ui
.FieldsetLayout( {
1381 label
: that
.displayText
1382 } ).addItems( items
)
1383 .$element
.appendTo( that
.$element
);
1385 if ( Util
.apiBool( pi
.dynamicparameters
) ) {
1386 dynamicFieldset
= new OO
.ui
.FieldsetLayout();
1387 dynamicParamNameWidget
= new OO
.ui
.TextInputWidget( {
1388 placeholder
: mw
.message( 'apisandbox-dynamic-parameters-add-placeholder' ).text()
1389 } ).on( 'enter', addDynamicParamWidget
);
1390 dynamicFieldset
.addItems( [
1391 new OO
.ui
.FieldLayout(
1392 new OO
.ui
.Widget( {} ).toggle( false ), {
1394 label
: Util
.parseHTML( pi
.dynamicparameters
)
1397 new OO
.ui
.ActionFieldLayout(
1398 dynamicParamNameWidget
,
1399 new OO
.ui
.ButtonWidget( {
1401 flags
: 'constructive'
1402 } ).on( 'click', addDynamicParamWidget
),
1404 label
: mw
.message( 'apisandbox-dynamic-parameters-add-label' ).text(),
1411 $( '<legend>' ).text( mw
.message( 'apisandbox-dynamic-parameters' ).text() ),
1412 dynamicFieldset
.$element
1414 .appendTo( that
.$element
);
1417 if ( deprecatedItems
.length
) {
1418 tmp
= new OO
.ui
.FieldsetLayout().addItems( deprecatedItems
).toggle( false );
1421 $( '<legend>' ).append(
1422 new OO
.ui
.ToggleButtonWidget( {
1423 label
: mw
.message( 'apisandbox-deprecated-parameters' ).text()
1424 } ).on( 'change', tmp
.toggle
, [], tmp
).$element
1428 .appendTo( that
.$element
);
1431 // Load stored params, if any, then update the booklet if we
1432 // have subpages (or else just update our valid-indicator).
1433 tmp
= that
.loadFromQueryParams
;
1434 that
.loadFromQueryParams
= null;
1435 if ( $.isPlainObject( tmp
) ) {
1436 that
.loadQueryParams( tmp
);
1438 if ( that
.getSubpages().length
> 0 ) {
1439 ApiSandbox
.updateUI( tmp
);
1441 that
.apiCheckValid();
1443 } ).fail( function ( code
, detail
) {
1444 that
.$element
.empty()
1446 new OO
.ui
.LabelWidget( {
1447 label
: mw
.message( 'apisandbox-load-error', that
.apiModule
, detail
).text(),
1448 classes
: [ 'error' ]
1450 new OO
.ui
.ButtonWidget( {
1451 label
: mw
.message( 'apisandbox-retry' ).text()
1452 } ).on( 'click', that
.loadParamInfo
, [], that
).$element
1458 * Check that all widgets on the page are in a valid state.
1462 ApiSandbox
.PageLayout
.prototype.apiCheckValid = function () {
1465 if ( this.paramInfo
=== null ) {
1466 return $.Deferred().resolve( false ).promise();
1468 return $.when
.apply( $, $.map( this.widgets
, function ( widget
) {
1469 return widget
.apiCheckValid();
1470 } ) ).then( function () {
1471 that
.apiIsValid
= $.inArray( false, arguments
) === -1;
1472 if ( that
.getOutlineItem() ) {
1473 that
.getOutlineItem().setIcon( that
.apiIsValid
|| suppressErrors
? null : 'alert' );
1474 that
.getOutlineItem().setIconTitle(
1475 that
.apiIsValid
|| suppressErrors
? '' : mw
.message( 'apisandbox-alert-page' ).plain()
1478 return $.Deferred().resolve( that
.apiIsValid
).promise();
1484 * Load form fields from query parameters
1486 * @param {Object} params
1488 ApiSandbox
.PageLayout
.prototype.loadQueryParams = function ( params
) {
1489 if ( this.paramInfo
=== null ) {
1490 this.loadFromQueryParams
= params
;
1492 $.each( this.widgets
, function ( name
, widget
) {
1493 var v
= params
.hasOwnProperty( name
) ? params
[ name
] : undefined;
1494 widget
.setApiValue( v
);
1500 * Load query params from form fields
1502 * @param {Object} params Write query parameters into this object
1503 * @param {Object} displayParams Write query parameters for display into this object
1505 ApiSandbox
.PageLayout
.prototype.getQueryParams = function ( params
, displayParams
) {
1506 $.each( this.widgets
, function ( name
, widget
) {
1507 var value
= widget
.getApiValue();
1508 if ( value
!== undefined ) {
1509 params
[ name
] = value
;
1510 if ( $.isFunction( widget
.getApiValueForDisplay
) ) {
1511 value
= widget
.getApiValueForDisplay();
1513 displayParams
[ name
] = value
;
1519 * Fetch a list of subpage names loaded by this page
1523 ApiSandbox
.PageLayout
.prototype.getSubpages = function () {
1525 $.each( this.widgets
, function ( name
, widget
) {
1527 if ( $.isFunction( widget
.getSubmodules
) ) {
1528 submodules
= widget
.getSubmodules();
1529 for ( i
= 0; i
< submodules
.length
; i
++ ) {
1531 key
: name
+ '=' + submodules
[ i
].value
,
1532 path
: submodules
[ i
].path
,
1533 prefix
: widget
.paramInfo
.submoduleparamprefix
|| ''
1542 * A text input with a clickable indicator
1547 * @param {Object} [config] Configuration options
1549 function TextInputWithIndicatorWidget( config
) {
1552 config
= config
|| {};
1553 TextInputWithIndicatorWidget
[ 'super' ].call( this, config
);
1555 this.$indicator
= $( '<span>' ).addClass( 'mw-apisandbox-clickable-indicator' );
1556 OO
.ui
.mixin
.TabIndexedElement
.call(
1557 this, $.extend( {}, config
, { $tabIndexed
: this.$indicator
} )
1560 this.input
= new OO
.ui
.TextInputWidget( $.extend( {
1561 $indicator
: this.$indicator
,
1562 disabled
: this.isDisabled()
1563 }, config
.input
) );
1565 // Forward most methods for convenience
1566 for ( k
in this.input
) {
1567 if ( $.isFunction( this.input
[ k
] ) && !this[ k
] ) {
1568 this[ k
] = this.input
[ k
].bind( this.input
);
1572 this.$indicator
.on( {
1573 click
: this.onIndicatorClick
.bind( this ),
1574 keypress
: this.onIndicatorKeyPress
.bind( this )
1577 this.$element
.append( this.input
.$element
);
1579 OO
.inheritClass( TextInputWithIndicatorWidget
, OO
.ui
.Widget
);
1580 OO
.mixinClass( TextInputWithIndicatorWidget
, OO
.ui
.mixin
.TabIndexedElement
);
1581 TextInputWithIndicatorWidget
.prototype.onIndicatorClick = function ( e
) {
1582 if ( !this.isDisabled() && e
.which
=== 1 ) {
1583 this.emit( 'indicator' );
1587 TextInputWithIndicatorWidget
.prototype.onIndicatorKeyPress = function ( e
) {
1588 if ( !this.isDisabled() && ( e
.which
=== OO
.ui
.Keys
.SPACE
|| e
.which
=== OO
.ui
.Keys
.ENTER
) ) {
1589 this.emit( 'indicator' );
1593 TextInputWithIndicatorWidget
.prototype.setDisabled = function ( disabled
) {
1594 TextInputWithIndicatorWidget
[ 'super' ].prototype.setDisabled
.call( this, disabled
);
1596 this.input
.setDisabled( this.isDisabled() );
1602 * A wrapper for a widget that provides an enable/disable button
1607 * @param {OO.ui.Widget} widget
1608 * @param {Object} [config] Configuration options
1610 function OptionalWidget( widget
, config
) {
1613 config
= config
|| {};
1615 this.widget
= widget
;
1616 this.$overlay
= config
.$overlay
||
1617 $( '<div>' ).addClass( 'mw-apisandbox-optionalWidget-overlay' );
1618 this.checkbox
= new OO
.ui
.CheckboxInputWidget( config
.checkbox
)
1619 .on( 'change', this.onCheckboxChange
, [], this );
1621 OptionalWidget
[ 'super' ].call( this, config
);
1623 // Forward most methods for convenience
1624 for ( k
in this.widget
) {
1625 if ( $.isFunction( this.widget
[ k
] ) && !this[ k
] ) {
1626 this[ k
] = this.widget
[ k
].bind( this.widget
);
1630 this.$overlay
.on( 'click', this.onOverlayClick
.bind( this ) );
1633 .addClass( 'mw-apisandbox-optionalWidget' )
1636 $( '<div>' ).addClass( 'mw-apisandbox-optionalWidget-fields' ).append(
1637 $( '<div>' ).addClass( 'mw-apisandbox-optionalWidget-widget' ).append(
1640 $( '<div>' ).addClass( 'mw-apisandbox-optionalWidget-checkbox' ).append(
1641 this.checkbox
.$element
1646 this.setDisabled( widget
.isDisabled() );
1648 OO
.inheritClass( OptionalWidget
, OO
.ui
.Widget
);
1649 OptionalWidget
.prototype.onCheckboxChange = function ( checked
) {
1650 this.setDisabled( !checked
);
1652 OptionalWidget
.prototype.onOverlayClick = function () {
1653 this.setDisabled( false );
1654 if ( $.isFunction( this.widget
.focus
) ) {
1655 this.widget
.focus();
1658 OptionalWidget
.prototype.setDisabled = function ( disabled
) {
1659 OptionalWidget
[ 'super' ].prototype.setDisabled
.call( this, disabled
);
1660 this.widget
.setDisabled( this.isDisabled() );
1661 this.checkbox
.setSelected( !this.isDisabled() );
1662 this.$overlay
.toggle( this.isDisabled() );
1666 $( ApiSandbox
.init
);
1668 }( jQuery
, mediaWiki
, OO
) );